package com.navinfo.platform.basicdatastatistics.utils.day;

import com.navinfo.platform.basicdatastatistics.dto.ExDataDto;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema;
import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.Metadata;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;

import java.util.ArrayList;
import java.util.List;

import static com.navinfo.platform.basicdatastatistics.utils.day.VehicleBasicDataSchema.getIntValue;

public class VehicleExDataSchema {

    public static StructType createSchema() {
        List<StructField> list = new ArrayList<>();
        list.add(new StructField("uid", DataTypes.LongType, true, Metadata.empty()));
        list.add(new StructField("tid", DataTypes.LongType, true, Metadata.empty()));
        list.add(new StructField("rpm_range500_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range600_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range700_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range800_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range900_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1000_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1100_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1200_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1300_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1400_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1500_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1600_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1700_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1800_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range1900_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2000_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2100_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2200_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2300_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2400_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2500_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2600_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2700_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2800_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range2900_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range3000_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("rpm_range_over3000_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range01_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range02_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range03_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range04_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range05_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range06_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range07_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range08_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range09_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range10_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range11_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("speed_range12_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("exceed_speed_range_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque0_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque10_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque20_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque30_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque40_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque50_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque60_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque70_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque80_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque90_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque99_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("torque100_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent0_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent10_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent20_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent30_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent40_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent50_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent60_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent70_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent80_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent90_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent99_urea", DataTypes.IntegerType, true, Metadata.empty()));
        list.add(new StructField("gas_open_percent100_urea", DataTypes.IntegerType, true, Metadata.empty()));

        return new StructType(list.toArray(new StructField[list.size()]));
    }

    /**
     * 创建一行数据
     */
    public static Row createRow(ExDataDto m, StructType schema) {
        List<Object> list = new ArrayList<>();
        list.add(m.getUid());
        list.add(m.getTid());
        list.add(getIntValue(m.getRpmRange500Urea()));
        list.add(getIntValue(m.getRpmRange600Urea()));
        list.add(getIntValue(m.getRpmRange700Urea()));
        list.add(getIntValue(m.getRpmRange800Urea()));
        list.add(getIntValue(m.getRpmRange900Urea()));
        list.add(getIntValue(m.getRpmRange1000Urea()));
        list.add(getIntValue(m.getRpmRange1100Urea()));
        list.add(getIntValue(m.getRpmRange1200Urea()));
        list.add(getIntValue(m.getRpmRange1300Urea()));
        list.add(getIntValue(m.getRpmRange1400Urea()));
        list.add(getIntValue(m.getRpmRange1500Urea()));
        list.add(getIntValue(m.getRpmRange1600Urea()));
        list.add(getIntValue(m.getRpmRange1700Urea()));
        list.add(getIntValue(m.getRpmRange1800Urea()));
        list.add(getIntValue(m.getRpmRange1900Urea()));
        list.add(getIntValue(m.getRpmRange2000Urea()));
        list.add(getIntValue(m.getRpmRange2100Urea()));
        list.add(getIntValue(m.getRpmRange2200Urea()));
        list.add(getIntValue(m.getRpmRange2300Urea()));
        list.add(getIntValue(m.getRpmRange2400Urea()));
        list.add(getIntValue(m.getRpmRange2500Urea()));
        list.add(getIntValue(m.getRpmRange2600Urea()));
        list.add(getIntValue(m.getRpmRange2700Urea()));
        list.add(getIntValue(m.getRpmRange2800Urea()));
        list.add(getIntValue(m.getRpmRange2900Urea()));
        list.add(getIntValue(m.getRpmRange3000Urea()));
        list.add(getIntValue(m.getRpmRangeOver3000Urea()));
        list.add(getIntValue(m.getSpeedRange01Urea()));
        list.add(getIntValue(m.getSpeedRange02Urea()));
        list.add(getIntValue(m.getSpeedRange03Urea()));
        list.add(getIntValue(m.getSpeedRange04Urea()));
        list.add(getIntValue(m.getSpeedRange05Urea()));
        list.add(getIntValue(m.getSpeedRange06Urea()));
        list.add(getIntValue(m.getSpeedRange07Urea()));
        list.add(getIntValue(m.getSpeedRange08Urea()));
        list.add(getIntValue(m.getSpeedRange09Urea()));
        list.add(getIntValue(m.getSpeedRange10Urea()));
        list.add(getIntValue(m.getSpeedRange11Urea()));
        list.add(getIntValue(m.getSpeedRange12Urea()));
        list.add(getIntValue(m.getExceedSpeedRangeUrea()));
        list.add(getIntValue(m.getTorque0Urea()));
        list.add(getIntValue(m.getTorque10Urea()));
        list.add(getIntValue(m.getTorque20Urea()));
        list.add(getIntValue(m.getTorque30Urea()));
        list.add(getIntValue(m.getTorque40Urea()));
        list.add(getIntValue(m.getTorque50Urea()));
        list.add(getIntValue(m.getTorque60Urea()));
        list.add(getIntValue(m.getTorque70Urea()));
        list.add(getIntValue(m.getTorque80Urea()));
        list.add(getIntValue(m.getTorque90Urea()));
        list.add(getIntValue(m.getTorque99Urea()));
        list.add(getIntValue(m.getTorque100Urea()));
        list.add(getIntValue(m.getGasOpenPercent0Urea()));
        list.add(getIntValue(m.getGasOpenPercent10Urea()));
        list.add(getIntValue(m.getGasOpenPercent20Urea()));
        list.add(getIntValue(m.getGasOpenPercent30Urea()));
        list.add(getIntValue(m.getGasOpenPercent40Urea()));
        list.add(getIntValue(m.getGasOpenPercent50Urea()));
        list.add(getIntValue(m.getGasOpenPercent60Urea()));
        list.add(getIntValue(m.getGasOpenPercent70Urea()));
        list.add(getIntValue(m.getGasOpenPercent80Urea()));
        list.add(getIntValue(m.getGasOpenPercent90Urea()));
        list.add(getIntValue(m.getGasOpenPercent99Urea()));
        list.add(getIntValue(m.getGasOpenPercent100Urea()));

        return new GenericRowWithSchema(list.toArray(), schema);
    }
}
